# TODO: Add comment
# 
# Author: Forever
###############################################################################
library(hydroGOF)
library(clusterSim)



inputPath = "C:/Users/Forever/Desktop/correl"
inputFile = "npp_pm"
listFile = list.files(path = inputPath,pattern=inputFile,full.names = TRUE,recursive=TRUE)
Size = length(listFile)

rs = data.frame()
for(i in 1:Size){
	filename = listFile[i]
	start_index = regexpr("_[1-9]",filename)+1
	end_index = regexpr("km.csv",filename)
	rt = substr(filename,start_index,end_index)
	data = read.csv(filename)
	data = subset(data,data[,1]!=3)
	sample = nrow(data)
	correl_pm1 = cor(data[,5],data[,8])
	correl_pm25 = cor(data[,6],data[,8])
	correl_pm10 = cor(data[,7],data[,8])
	
	correl_pm1 = round(correl_pm1,3)
	correl_pm25 = round(correl_pm25,3)
	correl_pm10 = round(correl_pm10,3)
	rs = rbind(rs,data.frame(rt,sample,correl_pm1,correl_pm25,correl_pm10))
}
outputFile = paste("C:/out2/",inputFile,".csv",sep="")
write.csv(rs,outputFile)
print("done")

